#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    int numSubarrayProductLessThanK(vector<int>& nums, int k)
    {
        int n = nums.size();
        int left = 0, right = 0;

        int count = 0;
        int mul = 1;

        while (right < n)
        {
            mul *= nums[right];
            while (left <= right && mul >= k)
            {
                mul /= nums[left];
                ++left;
            }

            int len = right - left + 1;
            count += len;

            ++right;
        }

        return count;
    }
};